// pages/backname/backname.js

var cardName = require("../untils/cardName.js");


Page({

  /**
   * 页面的初始数据
   */
  data: {
    cardList: {},
    searchList: {},
    showsearchList: false,
    searchKey: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      cardList: cardName.cardList
    })
  },


  onSearch: function (e) {
    let searchKey = e.detail.value;
    let that = this;
    Object.keys(this.data.cardList).forEach(function (key) {

      console.log(key, that.data.cardList[key]);
      let cardInfo = that.data.cardList[key];
      if (cardInfo.indexOf(searchKey) != -1) {
        that.data.searchList[key] = cardInfo
      }
    });

    if (Object.keys(this.data.searchList).length > 0) {

      this.setData({
        searchList: this.data.searchList,
        showsearchList: true
      })
      that.data.searchList = {};

    } else {
      this.setData({
        searchList: this.data.searchList,
        showsearchList: false
      })
    }
    //this.getCardInfo(e.detail.value);
  },

  onRemove: function (e) {
    this.setData({
      searchKey: ''
    })
  },


  // 点击选择银行卡
  onSelectBankTap: function (e) {


    let code = e.currentTarget.dataset.code;
    let pages = getCurrentPages();

    let addPage = pages[pages.length - 2];
    addPage.updateCardInfo(code);
    wx.navigateBack({
      delta: 1
    });
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})